package com.atguigu.daijia.customer.controller;

import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.customer.service.CustomerInfoService;
import com.atguigu.daijia.model.entity.customer.CustomerInfo;
import com.atguigu.daijia.model.form.customer.UpdateWxPhoneForm;
import com.atguigu.daijia.model.vo.customer.CustomerLoginVo;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/customer/info")
@SuppressWarnings({"unchecked", "rawtypes"})
public class CustomerInfoController {

	@Resource
	@Qualifier("customerInfoService")
	private CustomerInfoService customerInfoService;

	@Operation(summary = "获取客户基本信息")
	@GetMapping("/getCustomerInfo/{customerId}")
	public Result<CustomerInfo> getCustomerInfo(@PathVariable Long customerId) {
		return Result.ok(customerInfoService.getById(customerId));
	}
	
	/*
	 * @param code   微信授权编码
	 * @==============History===============<br/>;
	 * @Description //   微信小程序登录接口
	 * @Date 2024/7/31
	 * @Author < a href="15991488967@163.com">chen</ a>;
	 * @return com.atguigu.daijia.common.result.Result<java.lang.Long>
	 */
	@Operation(summary = "小程序授权登录")
	@GetMapping("/login/{code}")
	public Result<Long> login(@PathVariable String code) {
		return Result.ok(customerInfoService.login(code));
	}



	/*
	 * @param customerId 用户id
	 * @==============History===============<br/>
	 * @Description //   获取客户登录信息
	 * @Date 2024-7-31 20:32
	 * @Author < a href="15991488967@163.com">chen</ a>
	 * @return com.atguigu.daijia.common.result.Result<com.atguigu.daijia.model.vo.customer.CustomerLoginVo>
	 */
	@Operation(summary = "获取客户登录信息")
	@GetMapping("/getCustomerLoginInfo/{customerId}")
	public Result<CustomerLoginVo> getCustomerLoginInfo(@PathVariable Long customerId) {
		CustomerLoginVo customerLoginVo = customerInfoService.getCustomerInfo(customerId);
		return Result.ok(customerLoginVo);
	}


	/*
	 * @param updateWxPhoneForm
	 * @==============History===============<br/>;
	 * @Description //   更新客户微信手机号码
	 * @Date 2024/8/1
	 * @Author < a href="15991488967@163.com">chen</ a>;
	 */
	@Operation(summary = "更新客户微信手机号码")
	@PostMapping("/updateWxPhoneNumber")
	public Result<Boolean> updateWxPhoneNumber(@RequestBody UpdateWxPhoneForm updateWxPhoneForm) {
		return Result.ok(customerInfoService.updateWxPhoneNumber(updateWxPhoneForm));
	}


	
}

